﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Tracy.DataModel;
using TracyGUI.UIComponent;
using Tracy;
using Tracy.Messages;
using Tracy.Handlers;
using SharedLib.MessageFramework;
using System.Xml;

namespace TracyGUI
{
    public partial class FormMain : Form, IRecordLayout
    {
        public FormMain()
        {
            InitializeComponent();
            this.Icon = SharedResource.Tracy;
            LoadEntries();
            InitResources();
            InitMediaFiles();
            LoadEntryUltraExplorer();
            InitTagPanel();
            LoadLayout();
            //LoadFileUltraExplorer();
            TracyFacade.Instance.MessageDispatcher.OnNotifyUI += new EventHandler<Tracy.BasicServices.NotifyUIEventArgs>(MessageDispatcher_OnNotifyUI);
            TracyFacade.Instance.MessageDispatcher.OnException += new EventHandler<SharedLib.Exceptions.ExceptionEventArgs>(MessageDispatcher_OnException);
            TracyFacade.Instance.TaskScheduler.StartTimer();
        }

        private void FormMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            TracyFacade.Instance.Dispose();
            SaveLayout();
        }

        

        private void toolStripButtonScan_Click(object sender, EventArgs e)
        {
            //TODO: Scan a single entry
            TracyFacade.Instance.MessageDispatcher.EnqueueMessage(new TaskMessage(this, typeof(FeedScanHandler), null));
            TracyFacade.Instance.MessageDispatcher.EnqueueMessage(new TaskMessage(this, typeof(FileMonitorHandler), null));
            
        }

        private static void AddSubListViewItem(ListViewItem lvItem, string name, string text)
        {
            ListViewItem.ListViewSubItem lvSubItem = new ListViewItem.ListViewSubItem(lvItem, text);
            lvSubItem.Name = name;
            lvItem.SubItems.Add(lvSubItem);
        }

        private void FormMain_Load(object sender, EventArgs e)
        {

        }

        private void toolStripButtonAbout_Click(object sender, EventArgs e)
        {
            AboutBoxMain aboutBox = new AboutBoxMain();
            aboutBox.Show();
        }










    }

}
